package com.zmn.oms.third.youshu;

import com.alibaba.nacos.api.config.annotation.NacosValue;
import com.google.common.collect.Sets;
import com.zmn.common.utils.collection.CollectionUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.Set;

/**
 * 类描述：腾讯有数对接常量定义
 *
 * @author ligang
 * @date 2022/03/21 16:53
 */
@Component
public final class YouShuConsts {

    /**
     * 腾讯有数接入总开关
     */
    public static boolean POWER_ON;

    /**
     * 商家id (不区分环境)
     */
    public static final String MERCHANT_ID = "10004574";

    /**
     * 腾讯数据接入分配的应用ID
     */
    public static String APP_ID;

    /**
     * 腾讯数据接入分配的签名密钥
     */
    public static String APP_SECRET;

    /**
     * 接口上报加签算法
     */
    public static final String SIGN = "sha256";

    /**
     * 数据源id
     */
    public static String DATA_SOURCE_ID;

    /**
     * 渠道名称
     */
    public static final String CHANNEL_NAME = "腾讯有数-API";

    /**
     * 添加数据仓库
     */
    public static final String ADD_DATA_SOURCE_URL = "/data-api/v1/data_source/add";

    /**
     * 获取数据仓库
     */
    public static final String GET_DATA_SOURCE_URL = "/data-api/v1/data_source/get";

    /**
     * 订单添加/变更上报地址
     */
    public static final String ORDER_ADD_PUSH_URL = "/data-api/v1/order/add_order";

    /**
     * 订单状态变更上报地址
     */
    public static final String ORDER_UPDATE_PUSH_URL = "/data-api/v1/order/update";

    /**
     * 退货退款订单添加
     */
    public static final String ORDER_RETURN_PUSH_URL = "/data-api/v1/return_order/add";

    /**
     * 汇总订单添加/变更
     */
    public static final String ORDER_SUM_PUSH_URL = "/data-api/v1/order/add_order_sum";

    /**
     * 环境host
     */
    public static String HOST;

    /**
     * 上报至腾讯有数的二级渠道
     */
    public static Set<Integer> PUSH_CHANNEL_SET = Sets.newHashSet();

    /**
     * 根据环境获取host
     */
//    public static String getHost() {
//        if (Objects.equals(ACTIVE, "prod")) {
//            return "https://zhls.qq.com";
//        }
//        return "https://test.zhls.qq.com";
//    }

    /************************************  下面是动态配置 *************************************/
    @NacosValue(value = "${youshu.api.powerOn:false}", autoRefreshed = true)
    public void setPowerOn(boolean powerOn) {
        POWER_ON = powerOn;
    }

    @NacosValue(value = "${youshu.api.push.channel:0}", autoRefreshed = true)
    public void setPushChannelSet(List<Integer> channels) {
        if (CollectionUtil.isNullOrEmpty(channels)) {
            return;
        }
        PUSH_CHANNEL_SET = new HashSet<>(channels);
    }

    @NacosValue(value = "${youshu.api.app.id:''}", autoRefreshed = true)
    public void setAppId(String appId) {
        APP_ID = appId;
    }

    @NacosValue(value = "${youshu.api.app.secret:''}", autoRefreshed = true)
    public void setAppSecret(String secret) {
        APP_SECRET = secret;
    }

    @NacosValue(value = "${youshu.api.data.source.id:''}", autoRefreshed = true)
    public void setDataSourceId(String dataSourceId) {
        DATA_SOURCE_ID = dataSourceId;
    }

    @NacosValue(value = "${youshu.api.data.host:''}", autoRefreshed = true)
    public void setHost(String host) {
        HOST = host;
    }
}
